function Price = optbySVJEJ2(Strike,Times,Price,Rate,DividendYield,V0,ThetaV,Kappa,SigmaV,RhoSV,JumpFreq,mj,JumpVol,prob,mlow,slow,shigh)
%% ------------------------------description -----------------------------
%European call option prices using SVJEJ2 model
%Strike = strike price
%Times = time-to-maturity
%Price = current stock price
%Rate = interest rate
%DividendYield = dividend yield
%V0 = spot variance
%ThetaV = long-run variance
%Kappa = mean reversion
%SigmaV = volatility of volatility
%RhoSV = correlation coefficient between stock price and volatility
%JumpFreq = jump frequency
%mj = the mean jump size
%JumpVol = the jump size volatility
%prob = the probability of an downside jump
%mlow = the mean of the downside jump
%slow = the volatility of the upside jump
%shigh = the volatility of the upside jump
%Note: The mean of the upside jump is constrained by the other parameters so that the martingale restriction holds (see CFSVJEJ2).
%% -----------------------------------------------------------------------
AbsTol=1e-10;RelTol=1e-6;
Strike = Strike(:);Times = Times(:);
f1 = @(x)CFSVJEJ2(x,Price,Rate,DividendYield,Times,V0,ThetaV,Kappa,SigmaV,RhoSV,JumpFreq,mj,JumpVol,prob,mlow,slow,shigh,1);
p1 = 0.5 + NI(f1, Strike, AbsTol, RelTol);
            
f2 = @(x)CFSVJEJ2(x,Price,Rate,DividendYield,Times,V0,ThetaV,Kappa,SigmaV,RhoSV,JumpFreq,mj,JumpVol,prob,mlow,slow,shigh,0);
p2 = 0.5 + NI(f2, Strike, AbsTol, RelTol);
            
SEqTau = Price.*exp(-DividendYield.*Times);
KErTau = Strike.*exp(-Rate.*Times);
Price = SEqTau.*p1 - KErTau.*p2;
end

function Out = NI(IntegFun, Strike, AbsTol, RelTol)
s = warning('off', 'MATLAB:integral:NonFiniteValue');
lastwarn('');

Out = 1./pi.*integral(...
    @(Phi)real(exp(-1i.*Phi.*log(Strike)).*IntegFun(Phi)./(1i.*Phi)),...
    1e-9,Inf,'AbsTol',AbsTol,'RelTol',RelTol,'ArrayValued',true);

if any(isnan(Out(:)))
    [~, msgid] = lastwarn;
    if strcmpi(msgid,'MATLAB:integral:NonFiniteValue')
        warning(message('fininst:optSensByNI:problematicIntegrand'));
    end
end
warning(s);
end


